from django.db import models
from django.contrib.contenttypes import generic
from django.db.models import Q
from base import DataItem, TimeRelation
from core import Person
from structures import Position

class Term(TimeRelation):
    '''
    Time interval during which a given person has a given function
    '''
    position = models.ForeignKey(Position)
    person = models.ForeignKey(Person, related_name='terms')
    data = generic.GenericRelation(DataItem)

    class Meta:
        app_label = 'openpolitics'

    def __unicode__(self):
        return '%s (%s, %s)' % (self.person.name, self.position.name, self.position.institution.shortname)

